package com.example.administrator.printoutindemo;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class RecoveryInfo implements Serializable {

	private int _out_storage_detail_Id;
	private int _mid;
	private String _material_detail_id;
	private String _material;
	private String _fmnums;
	private String _projectId;


	// 将JSON对象转化为list
	public List<RecoveryInfo> getListFromJSON(String JsonStr) {
		List<RecoveryInfo> clist = new ArrayList<RecoveryInfo>();

		try {

			JSONArray jay = new JSONArray(JsonStr);// 将字符串转化为JSON数组

			for (int i = 0; i < jay.length(); i++) {
				JSONObject temp = (JSONObject) jay.get(i);

				RecoveryInfo n = new RecoveryInfo();

				n.set_material(temp.getString("material"));
				n.set_material_detail_id(temp.getString("material_detail_id"));
				n.set_fmnums(temp.getString("fmnums"));
				n.set_mid(Integer.parseInt(temp.getString("mid")));
				n.set_out_storage_detail_Id(Integer.parseInt(temp.getString("out_storage_detail_Id")));

				clist.add(n);

			}

		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}

		return clist;

	}

	public String ConvertToJson(RecoveryInfo model) {
		String jsonStr = "";
		JSONObject modelJsonObject = new JSONObject();
		try {
			modelJsonObject.put("out_storage_detail_Id", model.get_out_storage_detail_Id());
			modelJsonObject.put("mid", model.get_mid());
			modelJsonObject.put("material_detail_id", model.get_material_detail_id());
			modelJsonObject.put("fmnums", model.get_fmnums());
			modelJsonObject.put("material", model.get_material());
			modelJsonObject.put("projectId", model.get_projectId());


			jsonStr = modelJsonObject.toString();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonStr;
	}


	public String get_projectId() {
		return _projectId;
	}

	public void set_projectId(String _projectId) {
		this._projectId = _projectId;
	}

	public String get_fmnums() {
		return _fmnums;
	}

	public void set_fmnums(String _fmnums) {
		this._fmnums = _fmnums;
	}

	public int get_out_storage_detail_Id() {
		return _out_storage_detail_Id;
	}

	public void set_out_storage_detail_Id(int _out_storage_detail_Id) {
		this._out_storage_detail_Id = _out_storage_detail_Id;
	}

	public int get_mid() {
		return _mid;
	}

	public void set_mid(int _mid) {
		this._mid = _mid;
	}

	public String get_material_detail_id() {
		return _material_detail_id;
	}

	public void set_material_detail_id(String _material_detail_id) {
		this._material_detail_id = _material_detail_id;
	}

	public String get_material() {
		return _material;
	}

	public void set_material(String _material) {
		this._material = _material;
	}

}